package com.kaifamiao.annotation.type;

import com.kaifamiao.annotation.enums.MaritalStatus;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MaritalStatusTypeHandler implements TypeHandler<MaritalStatus> {

    @Override
    public void setParameter(PreparedStatement ps, int index , MaritalStatus ms , JdbcType jt )
            throws SQLException {
        ps.setString( index , ms.getStatus() );
    }

    @Override
    public MaritalStatus getResult(ResultSet rs, String label) throws SQLException {
        String status = rs.getString( label );
        return MaritalStatus.parse( status );
    }

    @Override
    public MaritalStatus getResult(ResultSet rs, int index) throws SQLException {
        String status = rs.getString( index );
        return MaritalStatus.parse( status );
    }

    @Override
    public MaritalStatus getResult(CallableStatement cs, int index) throws SQLException {
        String status = cs.getString( index );
        return MaritalStatus.parse( status );
    }
}
